package com.gxa.xiaoucomeshome.controller;

import com.gxa.xiaoucomeshome.exception.BusinessException;
import com.gxa.xiaoucomeshome.exception.ExceptionCode;
import com.gxa.xiaoucomeshome.pojo.Site;
import com.gxa.xiaoucomeshome.service.SiteService;
import com.gxa.xiaoucomeshome.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
@Api(value = "StoresController",tags="用户模块门店相关API接口")
@RestController
@RequestMapping("/stores")
@CrossOrigin
public class StoresController {

    @Autowired
    SiteService storesService;

    @ApiOperation(value = "查询门店列表")
    @PostMapping("/selectStores")
    public Map selectStoresByPage() throws BusinessException {

        List<Site> stores = storesService.selectByStoresPage();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(stores);
        return jsonResult.getMap();
    }
    @ApiOperation(value = "根据状态查询门店")
    @PostMapping("/selectByState")
    public Map selectByState(){
        Site site = storesService.selectByState();
        JsonResult jsonResult = new JsonResult();
        if (site==null){
            jsonResult.setCode("200");
            jsonResult.setMsg("请选择门店");
        }
        jsonResult.setCode("200");
        jsonResult.setData(site);
        return jsonResult.getMap();
    }
}
